package day24.edu;

import java.util.Objects;

// Created: 24/09/2025, ChangJiang Ru
public class User implements Comparable{
    private String name;
    private int age;

    public User()
    {

    }

    public User(String name, int age)
    {
        this.name = name;
        this.age = age;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return age == user.age && Objects.equals(name, user.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public int compareTo(Object o)
    {
        if(this == o)
        {
            return 0;
        }

        if (o instanceof User)
        {
            User user = (User)o;
            int value = this.age - ((User) o).age;
            if(value != 0)
            {
                return value;
            }
            return this.name.compareTo(((User) o).name);
        }

        throw new RuntimeException("Type not match");
    }

}
